﻿using UnityEngine;
using System.Collections;
using MessageSystem;
using BehaviorSystem;
namespace SkillSystem
{
    /// <summary>
    /// 技能释放组件
    /// </summary>
    public class SkillTransmitComponnent : ComponentBase, ISkillTransmitComponent
    {
        MessageTerminal messageTerminal;
        float time;
        bool isCanActive=true;
        public bool IsActive
        {
            get;set;
        }

        public SkillData CurSkillData { get; set; }

        public GameObject TargetObj { get; set; }

        void Start()
        {
            messageTerminal = GetComponent<MessageTerminal>();
              
            messageTerminal.RegisterMessage("SkillExcute", OnMessage);
            messageTerminal.RegisterMessage("TargetChange", OnMessage);

            //Test
            //TargetObj = new GameObject();
            //TargetObj.transform.position = this.transform.position + this.transform.forward * 3;
        }

        void Update()
        {
            if (isCanActive==false)
            {
                time += Time.deltaTime;
                if (time > 1)
                {
                    time = 0;
                    isCanActive = true;
                    DebugUtils.LogRedInfo("可以再释放了");
                }
            }

        }

        void OnMessage(IMessageArgs args)
        {
            
            if (args.MessageType== "SkillExcute")
            {
                ExcuteSkillArgs data = (ExcuteSkillArgs)args;
                if (isCanActive && TargetObj != null) 
                {
                    if (data != null && data.SkillID == CurSkillData.ID)
                    {
                        IsActive = true;
                        isCanActive = false;
                    }
                }
            }else if (args.MessageType == "TargetChange")
            {
                TargetChangeArgs data = (TargetChangeArgs)args;
                TargetObj = data.TargetObj ;
            }


        }
    }
}